package com.itheima.algorithm.hashtable;

import java.util.Arrays;

/**
 * @author: TylerZhong
 * @description:
 * 判断两个单词是否为字母异或次
 * 小写字母组成
 */
public class E06Leetcoce242 {

    /**
     * 输入：s = "anagram", t = "nagaram"
     * 输出：true
     *
     * 1. 拿到字符数组，排序后比较字符数组
     * 2. 字符大散放入 int[26], 比较数组
     */
    public boolean isAnagram(String s, String t) {
        return Arrays.equals(getKey(s), getKey(t));
    }

    public int[] getKey(String s) {
        int[] array = new int[26];
        char[] charArray = s.toCharArray();
        for (char ch : charArray) {
            array[ch - 'a']++;
        }
        return array;
    }

    public int[] getKey1(String s) {
        int[] array = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            array[ch - 'a']++;
        }
        return array;
    }

}
